package user_profile

import (
	"context"

	commonTools "algo-sdk-go/common/tools"
	"algo-sdk-go/project/matchmaking/application/dto"
	"algo-sdk-go/project/matchmaking/common/constant"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/logic/mate_preference"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/svc"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAllInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserAllInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAllInfoLogic {
	return &UserAllInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserAllInfoLogic) UserAllInfo(req *types.UserAllInfoRequest) (resp *types.UserAllinfoResponse, err error) {
	userAllInfo, err := l.svcCtx.UserProfileService.GetUserAllInfo(l.ctx, req.UserNumList)
	if err != nil {
		return nil, err
	}

	resp = &types.UserAllinfoResponse{
		Data: types.UserAllInfoData{
			UserInfoList: commonTools.Cast(userAllInfo, CastAllDataDto2Type),
		},
	}
	return
}

func CastAllDataDto2Type(userAllInfo dto.UserAllInfo) types.UserAllData {
	data := types.UserAllData{
		//ID:                       userAllInfo.UserProfile.Hometown,
		UserNum:       userAllInfo.UserProfile.UserNum,
		Name:          userAllInfo.UserProfile.Name,
		Gender:        userAllInfo.UserProfile.Gender.Value(),
		Height:        userAllInfo.UserProfile.Height,
		Weight:        userAllInfo.UserProfile.Weight,
		BirthDate:     userAllInfo.UserProfile.BirthDate,
		Age:           userAllInfo.UserProfile.Age,
		ChineseZodiac: userAllInfo.UserProfile.ChineseZodiac,
		MaritalStatus: userAllInfo.UserProfile.Status,
		Assets: types.Assets{
			AnnualIncome: userAllInfo.UserProfile.Assets.AnnualIncome,
			Car:          userAllInfo.UserProfile.Assets.Car.Value(),
			House:        userAllInfo.UserProfile.Assets.House.Value(),
		},
		Education:        userAllInfo.UserProfile.Education.Value(),
		Occupation:       userAllInfo.UserProfile.Occupation.Value(),
		IsPartyMember:    userAllInfo.UserProfile.IsPartyMember,
		Hometown:         userAllInfo.UserProfile.Hometown,
		CurrentResidence: userAllInfo.UserProfile.CurrentResidence,
		FamilyMembers:    types.FamilyMembers{},
		AgeRange: types.AgeRange{
			MinAge: userAllInfo.MatePreference.AgeRange.MinAge,
			MaxAge: userAllInfo.MatePreference.AgeRange.MaxAge,
		},
		MinHeight:                userAllInfo.MatePreference.HeightRange.MinHeight,
		MaxWeight:                userAllInfo.MatePreference.HeightRange.MaxHeight,
		MinIncome:                userAllInfo.MatePreference.IncomeRange.MinIncome,
		MinEducation:             userAllInfo.MatePreference.EducationRange.MinEducation.Value(),
		OccupationRequire:        commonTools.Cast(userAllInfo.MatePreference.OccupationPreference, constant.Occupation.Value),
		CurrentResidenceRequired: commonTools.Cast(userAllInfo.MatePreference.CurrentResidencePreference, mate_preference.DecodeAddress),
		HometownRequired:         commonTools.Cast(userAllInfo.MatePreference.HometownPreference, mate_preference.DecodeAddress),
		PersonalityTraits:        userAllInfo.MatePreference.PersonalityTraits,
		OtherRequired:            userAllInfo.MatePreference.OtherRequired,
		CreateUser:               "",
		ModifyUser:               "",
	}
	return data
}
